/**
 * @file 数据库配置
 * @description MongoDB数据库配置
 * @author Assistant
 * @date 2024-02-27
 */

import { MongooseModuleOptions } from '@nestjs/mongoose';

// MongoDB集合名称常量
export const COLLECTIONS = {
  GPS_LOGS: 'gps_parsed_records'
} as const;

// 索引配置
export const INDEXES = {
  TTL_DAYS: 30,
  BATCH_SIZE: 1000,
} as const;

// MongoDB字段验证规则
export const VALIDATORS = {
  LONGITUDE: { min: -180, max: 180 },
  LATITUDE: { min: -90, max: 90 },
  SPEED: { min: 0, max: 999 },
} as const;

// MongoDB连接配置
export const mongoConfig = (): { uri: string } => {
  const username = process.env.MONGO_USER || 'root';
  const password = process.env.MONGO_PASS || '123456';
  const host = process.env.MONGO_HOST || '127.0.0.1';
  const port = process.env.MONGO_PORT || '27017';
  const database = process.env.MONGO_DB_NAME || 'gps';

  return {
    uri: `mongodb://${username}:${password}@${host}:${port}/${database}?authSource=admin`,
  };
}; 